<template>
  <div>
    <div class="list">
      <div class="item" v-for="item in list" :key="item.id" >
        <div class="img">
          <img v-if="item.cover" :src="item.cover" style="object-fit: contain;" />
          <img v-else src="@/assets/images/PetCare/u0.png" />
        </div>
        <div class="content">
          <div class="title">宠物姓名：{{ item.petName }}</div>
          <div class="info">
            <div class="info-1">宠物品种：{{ item.variety }}</div>
            <div class="info-2">宠物性别：{{ item.sex }}</div>
            <div class="info-3">宠物年龄：{{ item.age }}</div>
          </div>
          <!-- <div class="text">注释：{{ item.comment }}</div> -->
        </div>
        <!-- <div class="update">
          <p>
            修改申请
          </p>
        </div>
        <div class="delete">
          <p>删除申请</p>
        </div> -->
      </div>
    </div>
    <div class="pagination">
      <el-pagination
        layout="prev, pager, next"
        :total="total"
        :page-size="pageSize"
        v-model:current-page="pageNum"
        @change="change"
      />
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import request from '@/utils/request.js'
const list = ref([])
const total = ref(0)
const pageNum = ref(1)
const pageSize = ref(6)

const init = (currentPage, pageSize) => {
  request
    .post(`/adoption/query?pageSize=${pageSize}&pageNum=${currentPage}`, {
      statusIn: ['unaudited','audited']
    })
    .then((res) => {
      list.value = res.data.records.filter((item) => !item.cause)
      total.value = res.data.total
      pageNum.value = res.data.current
      pageSize.value = res.data.size
    })
}

init(pageNum.value, pageSize.value)

const change = (currentPage, pageSize) => {
  init(currentPage, pageSize)
}
</script>

<style scoped>
.item {
  margin-bottom: 30px;
  display: flex;
  padding: 10px 20px;
  border-radius: 30px;
  border: 1px solid #09c199;
  background-color: #ffffff;
  .img {
    width: 360px;
    height: 189px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .content {
    margin-left: 20px;
    width: 800px;
    .info {
      margin-top: 15px;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      .info-1 {
        margin-right: 30px;
        flex: 1;
        width: 110px;
        /* background-color: rgb(9, 193, 153); */
        border-radius: 10px;
      }
      .info-2 {
        flex: 1;
        width: 30px;
        border-radius: 10px;
        /* background-color: rgb(2, 167, 240); */
      }
      .info-3 {
        flex: 1;
        color: black;
      }
    }
    .text {
      margin-top: 10px;
      height: 150px;
      overflow: hidden; /* 超出容器部分隐藏 */
      white-space: nowrap; /* 让文本在一行显示，超出容器部分不换行 */
      text-overflow: ellipsis; /* 超出容器部分显示省略号 */
      font-size: 16px;
    }
  }
  .update {
    margin-left: 250px;
    display: flex; /* 使用 flex 布局 */
    align-items: center; /* 垂直居中 */
    justify-content: center; /* 水平居中 */
    height: 179px;
    padding: 20px;
    border-right: 1px solid gray;
  }
  .delete {
    margin-left: 20px;
    display: flex; /* 使用 flex 布局 */
    align-items: center; /* 垂直居中 */
    justify-content: center; /* 水平居中 */
  }
}
.pagination {
  text-align: right;
  display: flex;
  flex-direction: row-reverse;
  margin-top: 20px;
  margin-bottom: 20px;
}
</style>
